package com.xml.util;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

/**
 * 读取properties文件的工具类
 *
 * @author xml E-Mail:kaioct@qq.com
 * @date 2021/3/8
 * @desc gridReportServerJava
 * @created 2021-03-08 11:14
 */
public final class PropertiesHelper {
    /**
     * 根据文件名称 和 键名称 获取对应的字符串String数据
     *
     * @param propertyFileName
     * @param propertyName
     * @return
     */
    public static String getString(String propertyFileName, String propertyName) {
        String data = "";
        try {
            Configuration config = new PropertiesConfiguration(propertyFileName);
            data = config.getString((propertyName));
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
        return data;
    }

    /**
     * 根据文件名称和键名称获取对应的长整形Long数据
     *
     * @param propertyFileName
     * @param propertyName
     * @return
     */
    public static Long getLong(String propertyFileName, String propertyName) {
        Long data = null;
        try {
            Configuration config = new PropertiesConfiguration(propertyFileName);
            data = config.getLong(propertyName, 0);
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
        return data;
    }

    /**
     * 根据文件名称和键名称获取对应的整形Integer数据
     *
     * @param propertyFileName
     * @param propertyName
     * @return
     */
    public static Integer getInteger(String propertyFileName, String propertyName) {
        Integer data = null;
        try {
            Configuration config = new PropertiesConfiguration(propertyFileName);
            data = config.getInt(propertyName, 0);
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
        return data;
    }


}
